home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / pxewin.zip / PXDIS.CPP < prev    next >
Text File  |  1992-02-04  |  6KB  |  241 lines

  1. // PXEWIN - (C) Copyright 1992 by Beam Engineering, INC.
  2.  
  3. // PXDIS.CPP //
  4.  
  5. // Contents ----------------------------------------------------------------
  6. //
  7. //    This module contains members for interfacing to the PXDIS class.
  8. //
  9. // End ---------------------------------------------------------------------
  10.  
  11. // External Reference Name for this Header ---------------------------------
  12.  
  13. #ifndef PXDIS_CPP
  14.     #define PXDIS_CPP
  15.  
  16. // End ---------------------------------------------------------------------
  17.  
  18. // Interface Dependencies --------------------------------------------------
  19.  
  20. #ifndef PXDIS_HPP
  21.     #include "pxdis.hpp"
  22. #endif // PXDIS_HPP //
  23.  
  24. // End ---------------------------------------------------------------------
  25.  
  26. // constructor PXDIS //
  27.  
  28. inline PXDIS::PXDIS()
  29. {
  30.     // NULL out all your field pointer.
  31.  
  32.     my_field = NULL;
  33.  
  34.     // Create some space for a new engine data pointer
  35.  
  36.     EngDataPtr = new EngData;
  37. }
  38.  
  39. // Summary -----------------------------------------------------------------
  40. //
  41. //    Set field pointer to null.  Create a Engine Data Pointer as a parent
  42. //    PXEngObject.
  43. //
  44. // End ---------------------------------------------------------------------
  45.  
  46. // member Get of PXDIS //
  47.  
  48. inline Pchar PXDIS::Get(int i)            /* Get the data from the
  49.                            right field */
  50. {
  51.     return my_field[i]->Get();
  52. }
  53.  
  54. // Summary -----------------------------------------------------------------
  55. //
  56. //    Gets the character version of the data in the field.
  57. //
  58. // Return Value
  59. //
  60. //    Returns character data.
  61. //
  62. // End ---------------------------------------------------------------------
  63.  
  64. // member SetUp of PXDIS //
  65.  
  66. int PXDIS::SetUp(int index,int mode,int op,int display)
  67. {
  68.     int i;                              /* Field index */
  69.     FIELDHANDLE fld;
  70.  
  71.     // Null out your pointers in case a delete is called before
  72.     // new
  73.  
  74.     my_field = NULL;
  75.     my_table = NULL;
  76.     my_record = NULL;
  77.  
  78.     // Open the table
  79.  
  80.     my_table = new PXTbl(EngDataPtr->PXEObjPtr);
  81.  
  82.     if(my_table->Open(index,mode,op) != PXSUCCESS)
  83.         return EngDataPtr->Errors.pxerr;
  84.  
  85.     // Open record buffer and get the number of records in table
  86.  
  87.     my_record = new PXRec(EngDataPtr->PXEObjPtr);
  88.     if(EngDataPtr->Errors.pxerr != PXSUCCESS)
  89.         return EngDataPtr->Errors.pxerr;
  90.  
  91.     // Get the number of fields in the table
  92.  
  93.     my_table->NumFlds();
  94.  
  95.     // Make an array of field pointers
  96.  
  97.     my_field = new PPXField [EngDataPtr->num_fields];
  98.  
  99.     // Get the fields initialized
  100.  
  101.     for(i = 0;i < EngDataPtr->num_fields;i++)
  102.     {
  103.         fld = i + 1;
  104.         my_field[i] = new PXField(my_record,fld);
  105.         if(EngDataPtr->Errors.pxerr != PXSUCCESS)
  106.             return EngDataPtr->Errors.pxerr;
  107.     }
  108.     return PXSUCCESS;
  109. }
  110.  
  111. // Summary -----------------------------------------------------------------
  112. //
  113. //    This member initializes the table, record and fields of a PDOX
  114. //    database.
  115. //
  116. // Parameters --------------------------------------------------------------
  117. //
  118. //    name.  This is the name of the database.
  119. //
  120. //    index.  This the index you wish to use.
  121. //
  122. //    mode.  This is the save mode you wish to open the table with.
  123. //
  124. //    op.  This is the operation you wish to perform on the table.  You
  125. //    can also use the create operation.
  126. //
  127. //    display.  This is the display option you wish to perform.  You can
  128. //    dislay a single record at a time or a page of records.
  129. //
  130. // Function Description ----------------------------------------------------
  131. //
  132. //    1.  Make table object.
  133. //
  134. //    2.  Make record object.
  135. //
  136. //    3.  Get the number of fields in the table.
  137. //
  138. //    4.  Make all your field objects.
  139. //
  140. // End ---------------------------------------------------------------------
  141.  
  142. // destructor PXDIS //
  143.  
  144. PXDIS::~PXDIS(void)
  145. {
  146.     int i;                /* field index */
  147.  
  148.     // if no pointer to my_field then set the number of fields to zero
  149.  
  150.     if(!my_field)
  151.         EngDataPtr->num_fields = 0;
  152.     for(i = 0;i < EngDataPtr->num_fields;i++)
  153.         delete my_field[i];
  154.     delete my_field;
  155.     delete my_record;
  156.     delete my_table;
  157.     delete EngDataPtr;
  158. }
  159.  
  160. // Description -------------------------------------------------------------
  161. //
  162. //    1.  Check and see if my_field is NULL.  If it is then set num_fields
  163. //        to zero so you can pass through the for loop.
  164. //
  165. //    2.  Delete the field objects.
  166. //
  167. //    3.  Delete the field pointer, record, table and Engine Data Pointers.
  168. //
  169. // End ---------------------------------------------------------------------
  170.  
  171. // member build of PXDIS //
  172.  
  173. PTStreamable PXDIS::build()
  174. {
  175.     return new PXDIS(streamableInit);
  176. }
  177.  
  178. TStreamableClass RegPXDIS("PXDIS",PXDIS::build,
  179.     __DELTA(PXDIS));
  180.  
  181. // Description -------------------------------------------------------------
  182. //
  183. //    When the streamable constructor is called, TStreamable dispatches
  184. //    the build member to construct the object.  To do this, it must
  185. //    know where to find this member functions for the specific class.
  186. //    This is the reason for the stream registration.
  187. //
  188. // End ---------------------------------------------------------------------
  189.  
  190. // member read of PXDIS //
  191.  
  192. inline Pvoid PXDIS::read(Ripstream is)
  193. {
  194.     PXEngObject::read(is);
  195.  
  196.     // NULL out all your field pointer.
  197.  
  198.     my_field = NULL;
  199.  
  200.     // Create some space for a new engine data pointer
  201.  
  202.     EngDataPtr = new EngData;
  203.     return this;
  204. }
  205.  
  206. // Summary -----------------------------------------------------------------
  207. //
  208. //    Read from the stream.
  209. //
  210. // Parameters
  211. //
  212. //    is.  Is the input stream.
  213. //
  214. // Return Value
  215. //
  216. //    Returns a pointer to this object to the TStreamable.
  217. //
  218. // Functional Description
  219. //
  220. //      Call the PXEngObject::read member to initialize the error status to
  221. //    no errors.  Null the field pointer.  Create a new Engine Data
  222. //    Pointer.  Nothing is taken from the stream.  This is here because
  223. //    the TStreamable constructor calls it.
  224. //
  225. // End ---------------------------------------------------------------------
  226.  
  227. // member write of PXDIS //
  228.  
  229. inline void PXDIS::write(Ropstream)
  230. {
  231.  
  232. }
  233.  
  234. // Summary -----------------------------------------------------------------
  235. //
  236. //    Nothing is put on the stream.
  237. //
  238. // End ---------------------------------------------------------------------
  239.  
  240. #endif // PXDIS_CPP //
  241.